/*
 * @Author: herw
 * @Date: 2020-11-13 14:32:02
 * @Last Modified by: herw
 * @Last Modified time: 2020-11-20 13:39:54
 */
<template>
  <el-dialog
    append-to-body
    :close-on-click-modal="false"
    :visible.sync="dialog"
    title="流程图"
    fullscreen
  >
    <img :src="imagePath" alt="流程图">
  </el-dialog>
</template>

<script>
import crud from '@/mixins/crud'
import { image } from '@/api/flowable/definition'

export default {
  name: 'ProcessImage',
  mixins: [crud],
  props: {
    processDefinitionId: {
      type: String,
      default: ''
    },
    processInstanceId: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      dialog: false,
      imagePath: ''
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    beforeInit() {
      if (this.processInstanceId && this.processInstanceId != null && this.processInstanceId !== '') {
        this.imagePath = `${process.env.VUE_APP_BASE_API}` + '/flowable/processInstanceImage?processInstanceId=' + this.processInstanceId + '&access_token=' + getToken() + '&time=' + new Date()
      } else if (this.processDefinitionId && this.processDefinitionId != null && this.processDefinitionId !== '') {
        image(this.processDefinitionId).then(res => {
          this.imagePath = 'data:image/png;base64,' + res
        }).catch(err => {
          console.log('error:' + err.response.data.message)
        })
      }
      return true
    }
  }
}
</script>

<style scoped>
</style>
